package com.xuetang9.fujian.threaddemo.bossdemo;

import java.util.concurrent.TimeUnit;

/**
 * @author: fujian
 * @description:
 * @date: 2021/5/3 9:26
 * @version: V1.0
 * @package: com.xuetang9.fujian.threaddemo.bossdemo
 **/
@SuppressWarnings("all")
public class Hero implements Runnable{
    private String name;
    private Boss boss;
    private int totalAttack;

    public Hero(String name, Boss boss) {
        this.name = name;
        this.boss = boss;
    }

    @Override
    public void run() {
        // 开启线程后，英雄不断进行攻击
        while (boss.getHp() > 0){
            boss.beAttacked(5);
            totalAttack += 5;
            try {
                TimeUnit.MILLISECONDS.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public int getTotalAttack() {
        return totalAttack;
    }

    public String getName() {
        return name;
    }
}
